﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Coater.Forms
{
    public partial class FormCoaterDiagnostics : Form
    {
        public FormCoaterDiagnostics()
        {
            InitializeComponent();

            this.gbDigitalInputs.Controls.SetChildIndex(DI_USWaferReady, 1);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_DSReadyForWafer, 2);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_Fluid1Level, 3);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_Fluid2Level, 4);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_Fluid3Level, 5);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_Fluid4Level, 6);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_Fluid5Level, 7);
            //this.gbDigitalInputs.Controls.SetChildIndex(DI_Fluid6Level, 8);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_WaferAtInput, 9);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_LidInterlock, 10);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_WaferAtExit, 11);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_WaferAtCenter, 12);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_WaferAtBelt, 13);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_ChuckSizeDetect, 14);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_WaferAtCounter, 15);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_UPSStatusInterlock, 17);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_ChuckReleaseBackPressure, 18);
            this.gbDigitalInputs.Controls.SetChildIndex(DI_WaferLeak, 19);

            ucTrbSpin.ValueChanged += (s, e) => lbSpeed_Spin.Text = $"Speed: {ucTrbSpin.Value.ToString()}";
            ucTrbSpinZ.ValueChanged += (s, e) => lbSpeed_SpinZ.Text = $"Speed: {ucTrbSpinZ.Value.ToString()}";
            ucTrbDispenseTheta.ValueChanged += (s, e) => lbSpeed_DispenseTheta.Text = $"Speed: {ucTrbDispenseTheta.Value.ToString()}";
            ucTrbDispenseZ.ValueChanged += (s, e) => lbSpeed_DispenseZ.Text = $"Speed: {ucTrbDispenseZ.Value.ToString()}";
            ucTrbSpanner.ValueChanged += (s, e) => lbSpeed_Spanner.Text = $"Speed: {ucTrbSpanner.Value.ToString()}";
            ucTrbWaferBelts.ValueChanged += (s, e) => lbSpeed_WaferBelts.Text = $"Speed: {ucTrbWaferBelts.Value.ToString()}";
        }

        private void FormCoaterDiagnostics_Load(object sender, EventArgs e)
        {
            if (DeviceContext.Instance.Config.Coater.EnableBacksideNozzle6)
            {
                this.gbDigitalInputs.Controls.SetChildIndex(DI_Fluid6Level, 8);
                DI_Fluid6Level.Title = "Fluid 6 Level";
            }
            else
            {
                this.gbDigitalInputs.Controls.SetChildIndex(DI_Fluid6Level, 16);
                DI_Fluid6Level.Title = "External Sensor";
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnKeypad_Click(object sender, EventArgs e)
        {
            this.panelKeypad.Visible = !this.panelKeypad.Visible;
        }
    }
}
